package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.entity.SealTop10Flag;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /*
    * 插入下单数据
    * */
    void insert(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /*
    * 根据id查询订单
    * */
    @Select("SELECT * FROM orders WHERE id = #{id}")
    Orders selectOrderById(Long id);

    Page<OrderVO> pageSelect(OrdersPageQueryDTO ordersPageQueryDTO);

    Integer selectOrderStatusCount(Map map);

    @Select("SELECT * FROM orders WHERE status = #{status} AND order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    Double returnOverMoneyByDay(Map map);
    @Select("SELECT order_detail.name name,dish_id,setmeal_id,order_detail.number number FROM orders,order_detail " +
            "WHERE order_time > #{beginTime} AND order_time < #{endTime} " +
            "AND status = #{status} " +
            "AND orders.id = order_detail.order_id")
    List<SealTop10Flag> salesTop10Flag(Map map);

    Double getCompleteOrdersAVGAmount(Map map);
}
